package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing")
@Api(tags = "护理计划管理")
@Slf4j
public class NursingPlanController {

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 获取所有护理计划
     * @return
     */
    @GetMapping("/plan")
    @ApiOperation("获取所有护理计划")
    public ResponseResult<List<NursingPlanVo>> all (){
        List<NursingPlanVo> nursingPlanVos = nursingPlanService.all();
        return ResponseResult.success(nursingPlanVos);
    }

    /**
     * 添加护理计划
     * @return
     */
    @PostMapping("/plan")
    @ApiOperation("添加护理计划")
    public ResponseResult add (@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.add(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 分页条件查询护理计划
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/plan/search")
    @ApiModelProperty(value = "分页条件查询护理计划")
    public ResponseResult<PageResponse<NursingPlanVo>> getByPage(String name,
                                    @RequestParam(defaultValue = "1") Integer pageNum,
                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                    Integer status) {
        PageResponse<NursingPlanVo> page = nursingPlanService.getByPage(name, pageNum, pageSize, status);
        return ResponseResult.success(page);
    }

    /**
     * 根据id查询护理计划
     * @return
     */
    @GetMapping("/plan/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult<NursingPlanVo> getById(@PathVariable Long id){
        NursingPlanVo nursingPlanVos = nursingPlanService.getById(id);
        return ResponseResult.success(nursingPlanVos);
    }

    /**
     * 编辑更新护理计划
     * @return
     */
    @PutMapping("/plan/{id}")
    @ApiOperation("编辑更新护理计划")
    public ResponseResult update (@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.update(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 删除护理计划
     * @return
     */
    @DeleteMapping("/plan/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult deleteById(@PathVariable Long id){
        nursingPlanService.deleteById(id);
        return ResponseResult.success();
    }

    /**
     * 启用禁用护理计划
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用护理计划")
    public ResponseResult enableDisable (@PathVariable Long id, @PathVariable Integer status) {
        log.info("启用禁用护理计划，id:{},status:{}",id,status);
        nursingPlanService.enableDisable(id, status);
        return ResponseResult.success();
    }

}
